{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import statsmodels\n",
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "from scipy import stats\n",
    "import warnings;\n",
    "from pysqldf import SQLDF\n",
    "import pandasql as psql\n",
    "from matplotlib.ticker import FuncFormatter\n",
    "from sklearn.model_selection import KFold\n",
    "import sklearn.ensemble as ske\n",
    "import lightgbm as lgb\n",
    "from pandas.api.types import is_string_dtype\n",
    "from pandas.api.types import is_numeric_dtype\n",
    "import xgboost as xgb\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_squared_error\n",
    "from math import sqrt\n",
    "\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "train01 = pd.read_csv(\"C:\\\\Kaggle\\\\Cars\\\\Data\\\\TrnDataForLGB.csv\")\n",
    "test01 = pd.read_csv(\"C:\\\\Kaggle\\\\Cars\\\\Data\\\\TstDataForLGB.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['CompNameCarName_FABIA',\n",
       " 'LocationChennai',\n",
       " 'CompName_FORD',\n",
       " 'CompNameCarName_FIGO',\n",
       " 'CompName_AUDI',\n",
       " 'CompNameCarName_X3',\n",
       " 'LocationHyderabad',\n",
       " 'CompNameCarName_PAJERO',\n",
       " 'CompNameCarName_KWID',\n",
       " 'CompNameCarName_CRETA',\n",
       " 'CompNameCarName_DUSTER',\n",
       " 'CompNameCarName_ETIOS',\n",
       " 'CompNameCarName_KUV',\n",
       " 'CompNameCarName_VERNA',\n",
       " 'CompNameCarName_5',\n",
       " 'Mileage',\n",
       " 'CompNameCarName_MOBILIO',\n",
       " 'Fuel_TypeCNG',\n",
       " 'CompNameCarName_RITZ',\n",
       " 'CompNameCarName_OPTRA',\n",
       " 'CompNameCarName_ACCENT',\n",
       " 'CompNameCarName_SANTA',\n",
       " 'CompNameCarName_ALTO',\n",
       " 'CompNameCarName_XYLO',\n",
       " 'CompName_JEEP',\n",
       " 'LocationMumbai',\n",
       " 'CompNameCarName_CITY',\n",
       " 'CompNameCarName_WAGON',\n",
       " 'CompNameCarName_SANTRO',\n",
       " 'LocationPune',\n",
       " 'CompName_MERCEDES-BENZ',\n",
       " 'CompNameCarName_ELANTRA',\n",
       " 'CompNameCarName_DZIRE',\n",
       " 'CompNameCarName_BRIO',\n",
       " 'CompNameCarName_Q5',\n",
       " 'CompNameCarName_SWIFT',\n",
       " 'CompNameCarName_EECO',\n",
       " 'CompNameCarName_BOLERO',\n",
       " 'CompName_FIAT',\n",
       " 'CompNameCarName_I10',\n",
       " 'CompNameCarName_TERRANO',\n",
       " 'CompName_NISSAN',\n",
       " 'LocationJaipur',\n",
       " 'LocationKochi',\n",
       " 'CompNameCarName_E-CLASS',\n",
       " 'CompNameCarName_IKON',\n",
       " 'Fuel_TypeLPG',\n",
       " 'CompNameCarName_XUV500',\n",
       " 'CompNameCarName_ENDEAVOUR',\n",
       " 'CompNameCarName_OMNI',\n",
       " 'CompNameCarName_BALENO',\n",
       " 'CompNameCarName_CIVIC',\n",
       " 'CompNameCarName_M-CLASS',\n",
       " 'CompNameCarName_CR-V',\n",
       " 'Engine',\n",
       " 'New_Price',\n",
       " 'CompNameCarName_SSANGYONG',\n",
       " 'CompNameCarName_SUNNY',\n",
       " 'Owner_TypeThird',\n",
       " 'CompNameCarName_JAZZ',\n",
       " 'CompName_RENAULT',\n",
       " 'CompNameCarName_VITARA',\n",
       " 'CompNameCarName_I20',\n",
       " 'CompNameCarName_ACCORD',\n",
       " 'CompNameCarName_INDIGO',\n",
       " 'CompNameCarName_LAURA',\n",
       " 'CompNameCarName_TIAGO',\n",
       " 'CompNameCarName_MICRA',\n",
       " 'CompNameCarName_NEW',\n",
       " 'Kilometers_Driven',\n",
       " 'CompNameCarName_MANZA',\n",
       " 'CompNameCarName_INNOVA',\n",
       " 'CompNameCarName_XF',\n",
       " 'Lag_Price2',\n",
       " 'CompName_HYUNDAI',\n",
       " 'CompName_LAND',\n",
       " 'Owner_TypeSecond',\n",
       " 'Power',\n",
       " 'CompNameCarName_AVEO',\n",
       " 'CompNameCarName_SX4',\n",
       " 'CompNameCarName_AMAZE',\n",
       " 'CompNameCarName_CELERIO',\n",
       " 'CompNameCarName_CLA',\n",
       " 'Lag_Price4',\n",
       " 'CompNameCarName_SUPERB',\n",
       " 'CompNameCarName_BEAT',\n",
       " 'CompName_TOYOTA',\n",
       " 'CompNameCarName_A-STAR',\n",
       " 'Fuel_TypeElectric',\n",
       " 'CompName_DATSUN',\n",
       " 'CompNameCarName_Q3',\n",
       " 'CompNameCarName_COROLLA',\n",
       " 'CompNameCarName_GLE',\n",
       " 'CompNameCarName_ROVER',\n",
       " 'CompName_MAHINDRA',\n",
       " 'CompNameCarName_S',\n",
       " 'LocationAhmedabad',\n",
       " 'Owner_TypeFirst',\n",
       " 'CompName_CHEVROLET',\n",
       " 'CompNameCarName_OCTAVIA',\n",
       " 'CompNameCarName_GL-CLASS',\n",
       " 'CompNameCarName_GRAND',\n",
       " 'CompName_VOLKSWAGEN',\n",
       " 'CompNameCarName_RAPID',\n",
       " 'CompNameCarName_FIESTA',\n",
       " 'CompNameCarName_COOPER',\n",
       " 'CompName_VOLVO',\n",
       " 'TransmissionManual',\n",
       " 'CompNameCarName_B',\n",
       " 'CompName_MITSUBISHI',\n",
       " 'CompNameCarName_POLO',\n",
       " 'CompNameCarName_Q7',\n",
       " 'CompNameCarName_X1',\n",
       " 'CompNameCarName_ERTIGA',\n",
       " 'CompNameCarName_LINEA',\n",
       " 'CompName_JAGUAR',\n",
       " 'Owner_TypeFourth...Above',\n",
       " 'CompName_MINI',\n",
       " 'CompName_TATA',\n",
       " 'LocationBangalore',\n",
       " 'Fuel_TypePetrol',\n",
       " 'CompNameCarName_JETTA',\n",
       " 'CompNameCarName_A4',\n",
       " 'CompName_SKODA',\n",
       " 'CompNameCarName_CAMRY',\n",
       " 'CompNameCarName_800',\n",
       " 'CompNameCarName_ECOSPORT',\n",
       " 'CompNameCarName_NANO',\n",
       " 'Year',\n",
       " 'CompName_BMW',\n",
       " 'CompNameCarName_AMEO',\n",
       " 'CompNameCarName_FORTUNER',\n",
       " 'LocationKolkata',\n",
       " 'CompName_MARUTI',\n",
       " 'CompNameCarName_GLA',\n",
       " 'CompNameCarName_COMPASS',\n",
       " 'CompNameCarName_INDICA',\n",
       " 'CompNameCarName_7',\n",
       " 'CompNameCarName_EON',\n",
       " 'LocationDelhi',\n",
       " 'CompNameCarName_A6',\n",
       " 'CompNameCarName_CIAZ',\n",
       " 'CompNameCarName_XCENT',\n",
       " 'CompNameCarName_SCORPIO',\n",
       " 'CompNameCarName_VENTO',\n",
       " 'CompName_HONDA',\n",
       " 'CompNameCarName_3',\n",
       " 'CompNameCarName_ZEN',\n",
       " 'CompName_PORSCHE',\n",
       " 'CompNameCarName_CRUZE',\n",
       " 'CompNameCarName_ZEST',\n",
       " 'CompNameCarName_ELITE',\n",
       " 'TransmissionAutomatic',\n",
       " 'Seats',\n",
       " 'LocationCoimbatore',\n",
       " 'Fuel_TypeDiesel',\n",
       " 'CompNameCarName_X5']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Remove_List = [\"id\",\"Price\",\"Name\",\"Lag_Price2_MIN\",\"Lag_Price2_MAX\",\n",
    "               \"Lag_Price3_MIN\",\"Lag_Price3_MAX\",\"Lag_Price\",\"Lag_Price3\",\"Engine_Group\",\n",
    "               \"Power_Group\",\"TrainTestInd\",\"CarCompName\",\"RateChng1\",\"RateChng2\",\"RateChng3\",\n",
    "               \"Lag_Price4_MIN\",\"Lag_Price4_MAX\",\"Lag_Price4_MIN_BY_MAX\"]\n",
    "feature_names = list(set(list(train01.columns)) - set(Remove_List))\n",
    "feature_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train02 = train01.copy(deep=True)\n",
    "train02.reset_index(drop = True, inplace = True)\n",
    "kf = KFold(n_splits = 5, shuffle = True, random_state = 100)\n",
    "kf.get_n_splits(train02)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running CV Iteration Num : 1\n",
      "Training until validation scores don't improve for 400 rounds.\n",
      "[200]\tvalid_0's rmse: 0.381105\n",
      "[400]\tvalid_0's rmse: 0.244997\n",
      "[600]\tvalid_0's rmse: 0.198507\n",
      "[800]\tvalid_0's rmse: 0.179467\n",
      "[1000]\tvalid_0's rmse: 0.169416\n",
      "[1200]\tvalid_0's rmse: 0.163913\n",
      "[1400]\tvalid_0's rmse: 0.160069\n",
      "[1600]\tvalid_0's rmse: 0.157185\n",
      "[1800]\tvalid_0's rmse: 0.154881\n",
      "[2000]\tvalid_0's rmse: 0.152933\n",
      "[2200]\tvalid_0's rmse: 0.151392\n",
      "[2400]\tvalid_0's rmse: 0.149863\n",
      "[2600]\tvalid_0's rmse: 0.148605\n",
      "[2800]\tvalid_0's rmse: 0.14734\n",
      "[3000]\tvalid_0's rmse: 0.146211\n",
      "[3200]\tvalid_0's rmse: 0.145119\n",
      "[3400]\tvalid_0's rmse: 0.144296\n",
      "[3600]\tvalid_0's rmse: 0.143381\n",
      "[3800]\tvalid_0's rmse: 0.142552\n",
      "[4000]\tvalid_0's rmse: 0.141794\n",
      "[4200]\tvalid_0's rmse: 0.141099\n",
      "[4400]\tvalid_0's rmse: 0.14043\n",
      "[4600]\tvalid_0's rmse: 0.139806\n",
      "[4800]\tvalid_0's rmse: 0.139188\n",
      "[5000]\tvalid_0's rmse: 0.138475\n",
      "[5200]\tvalid_0's rmse: 0.138043\n",
      "[5400]\tvalid_0's rmse: 0.137581\n",
      "[5600]\tvalid_0's rmse: 0.137138\n",
      "[5800]\tvalid_0's rmse: 0.136641\n",
      "[6000]\tvalid_0's rmse: 0.136208\n",
      "[6200]\tvalid_0's rmse: 0.135916\n",
      "[6400]\tvalid_0's rmse: 0.135497\n",
      "[6600]\tvalid_0's rmse: 0.135103\n",
      "[6800]\tvalid_0's rmse: 0.134769\n",
      "[7000]\tvalid_0's rmse: 0.134425\n",
      "[7200]\tvalid_0's rmse: 0.134122\n",
      "[7400]\tvalid_0's rmse: 0.133837\n",
      "[7600]\tvalid_0's rmse: 0.133593\n",
      "[7800]\tvalid_0's rmse: 0.133355\n",
      "[8000]\tvalid_0's rmse: 0.133042\n",
      "[8200]\tvalid_0's rmse: 0.132739\n",
      "[8400]\tvalid_0's rmse: 0.132451\n",
      "[8600]\tvalid_0's rmse: 0.132162\n",
      "[8800]\tvalid_0's rmse: 0.131905\n",
      "[9000]\tvalid_0's rmse: 0.131718\n",
      "[9200]\tvalid_0's rmse: 0.131567\n",
      "[9400]\tvalid_0's rmse: 0.131374\n",
      "[9600]\tvalid_0's rmse: 0.131179\n",
      "[9800]\tvalid_0's rmse: 0.130992\n",
      "[10000]\tvalid_0's rmse: 0.130876\n",
      "[10200]\tvalid_0's rmse: 0.130681\n",
      "[10400]\tvalid_0's rmse: 0.130537\n",
      "[10600]\tvalid_0's rmse: 0.130372\n",
      "[10800]\tvalid_0's rmse: 0.130176\n",
      "[11000]\tvalid_0's rmse: 0.130103\n",
      "[11200]\tvalid_0's rmse: 0.129988\n",
      "[11400]\tvalid_0's rmse: 0.12984\n",
      "[11600]\tvalid_0's rmse: 0.129662\n",
      "[11800]\tvalid_0's rmse: 0.12957\n",
      "[12000]\tvalid_0's rmse: 0.129431\n",
      "[12200]\tvalid_0's rmse: 0.129317\n",
      "[12400]\tvalid_0's rmse: 0.129182\n",
      "[12600]\tvalid_0's rmse: 0.129056\n",
      "[12800]\tvalid_0's rmse: 0.128982\n",
      "[13000]\tvalid_0's rmse: 0.128872\n",
      "[13200]\tvalid_0's rmse: 0.128789\n",
      "[13400]\tvalid_0's rmse: 0.128726\n",
      "[13600]\tvalid_0's rmse: 0.128645\n",
      "[13800]\tvalid_0's rmse: 0.128566\n",
      "[14000]\tvalid_0's rmse: 0.128466\n",
      "[14200]\tvalid_0's rmse: 0.12836\n",
      "[14400]\tvalid_0's rmse: 0.128262\n",
      "[14600]\tvalid_0's rmse: 0.12822\n",
      "[14800]\tvalid_0's rmse: 0.128113\n",
      "[15000]\tvalid_0's rmse: 0.128076\n",
      "[15200]\tvalid_0's rmse: 0.127981\n",
      "[15400]\tvalid_0's rmse: 0.127928\n",
      "[15600]\tvalid_0's rmse: 0.127872\n",
      "[15800]\tvalid_0's rmse: 0.127843\n",
      "[16000]\tvalid_0's rmse: 0.127779\n",
      "[16200]\tvalid_0's rmse: 0.127712\n",
      "[16400]\tvalid_0's rmse: 0.127646\n",
      "[16600]\tvalid_0's rmse: 0.127639\n",
      "[16800]\tvalid_0's rmse: 0.127588\n",
      "[17000]\tvalid_0's rmse: 0.127571\n",
      "[17200]\tvalid_0's rmse: 0.127526\n",
      "[17400]\tvalid_0's rmse: 0.127527\n",
      "[17600]\tvalid_0's rmse: 0.127505\n",
      "[17800]\tvalid_0's rmse: 0.127476\n",
      "[18000]\tvalid_0's rmse: 0.12746\n",
      "[18200]\tvalid_0's rmse: 0.127478\n",
      "Early stopping, best iteration is:\n",
      "[17966]\tvalid_0's rmse: 0.127444\n",
      "Test RMSE :  0.12744399164285153\n",
      "Running CV Iteration Num : 2\n",
      "Training until validation scores don't improve for 400 rounds.\n",
      "[200]\tvalid_0's rmse: 0.379675\n",
      "[400]\tvalid_0's rmse: 0.246319\n",
      "[600]\tvalid_0's rmse: 0.202213\n",
      "[800]\tvalid_0's rmse: 0.183803\n",
      "[1000]\tvalid_0's rmse: 0.174213\n",
      "[1200]\tvalid_0's rmse: 0.168747\n",
      "[1400]\tvalid_0's rmse: 0.165406\n",
      "[1600]\tvalid_0's rmse: 0.162717\n",
      "[1800]\tvalid_0's rmse: 0.160412\n",
      "[2000]\tvalid_0's rmse: 0.158692\n",
      "[2200]\tvalid_0's rmse: 0.157151\n",
      "[2400]\tvalid_0's rmse: 0.155706\n",
      "[2600]\tvalid_0's rmse: 0.154355\n",
      "[2800]\tvalid_0's rmse: 0.153173\n",
      "[3000]\tvalid_0's rmse: 0.152221\n",
      "[3200]\tvalid_0's rmse: 0.151198\n",
      "[3400]\tvalid_0's rmse: 0.150189\n",
      "[3600]\tvalid_0's rmse: 0.149361\n",
      "[3800]\tvalid_0's rmse: 0.148548\n",
      "[4000]\tvalid_0's rmse: 0.147811\n",
      "[4200]\tvalid_0's rmse: 0.147146\n",
      "[4400]\tvalid_0's rmse: 0.14656\n",
      "[4600]\tvalid_0's rmse: 0.145943\n",
      "[4800]\tvalid_0's rmse: 0.145381\n",
      "[5000]\tvalid_0's rmse: 0.144838\n",
      "[5200]\tvalid_0's rmse: 0.144301\n",
      "[5400]\tvalid_0's rmse: 0.143754\n",
      "[5600]\tvalid_0's rmse: 0.143288\n",
      "[5800]\tvalid_0's rmse: 0.142839\n",
      "[6000]\tvalid_0's rmse: 0.142406\n",
      "[6200]\tvalid_0's rmse: 0.142039\n",
      "[6400]\tvalid_0's rmse: 0.141633\n",
      "[6600]\tvalid_0's rmse: 0.141267\n",
      "[6800]\tvalid_0's rmse: 0.140944\n",
      "[7000]\tvalid_0's rmse: 0.140553\n",
      "[7200]\tvalid_0's rmse: 0.140253\n",
      "[7400]\tvalid_0's rmse: 0.139965\n",
      "[7600]\tvalid_0's rmse: 0.139693\n",
      "[7800]\tvalid_0's rmse: 0.139397\n",
      "[8000]\tvalid_0's rmse: 0.139233\n",
      "[8200]\tvalid_0's rmse: 0.139009\n",
      "[8400]\tvalid_0's rmse: 0.138802\n",
      "[8600]\tvalid_0's rmse: 0.138549\n",
      "[8800]\tvalid_0's rmse: 0.138296\n",
      "[9000]\tvalid_0's rmse: 0.138107\n",
      "[9200]\tvalid_0's rmse: 0.137788\n",
      "[9400]\tvalid_0's rmse: 0.137524\n",
      "[9600]\tvalid_0's rmse: 0.137231\n",
      "[9800]\tvalid_0's rmse: 0.137072\n",
      "[10000]\tvalid_0's rmse: 0.136911\n",
      "[10200]\tvalid_0's rmse: 0.136769\n",
      "[10400]\tvalid_0's rmse: 0.136576\n",
      "[10600]\tvalid_0's rmse: 0.136374\n",
      "[10800]\tvalid_0's rmse: 0.136199\n",
      "[11000]\tvalid_0's rmse: 0.13598\n",
      "[11200]\tvalid_0's rmse: 0.135767\n",
      "[11400]\tvalid_0's rmse: 0.135623\n",
      "[11600]\tvalid_0's rmse: 0.135493\n",
      "[11800]\tvalid_0's rmse: 0.135346\n",
      "[12000]\tvalid_0's rmse: 0.135228\n",
      "[12200]\tvalid_0's rmse: 0.135115\n",
      "[12400]\tvalid_0's rmse: 0.135027\n",
      "[12600]\tvalid_0's rmse: 0.135021\n",
      "[12800]\tvalid_0's rmse: 0.134975\n",
      "[13000]\tvalid_0's rmse: 0.134931\n",
      "[13200]\tvalid_0's rmse: 0.134844\n",
      "[13400]\tvalid_0's rmse: 0.134728\n",
      "[13600]\tvalid_0's rmse: 0.134613\n",
      "[13800]\tvalid_0's rmse: 0.134489\n",
      "[14000]\tvalid_0's rmse: 0.134432\n",
      "[14200]\tvalid_0's rmse: 0.134327\n",
      "[14400]\tvalid_0's rmse: 0.134281\n",
      "[14600]\tvalid_0's rmse: 0.134202\n",
      "[14800]\tvalid_0's rmse: 0.134185\n",
      "[15000]\tvalid_0's rmse: 0.134128\n",
      "[15200]\tvalid_0's rmse: 0.134021\n",
      "[15400]\tvalid_0's rmse: 0.133948\n",
      "[15600]\tvalid_0's rmse: 0.133907\n",
      "[15800]\tvalid_0's rmse: 0.133825\n",
      "[16000]\tvalid_0's rmse: 0.133773\n",
      "[16200]\tvalid_0's rmse: 0.133733\n",
      "[16400]\tvalid_0's rmse: 0.133638\n",
      "[16600]\tvalid_0's rmse: 0.133602\n",
      "[16800]\tvalid_0's rmse: 0.133519\n",
      "[17000]\tvalid_0's rmse: 0.133503\n",
      "[17200]\tvalid_0's rmse: 0.133456\n",
      "[17400]\tvalid_0's rmse: 0.133429\n",
      "[17600]\tvalid_0's rmse: 0.133357\n",
      "[17800]\tvalid_0's rmse: 0.133332\n",
      "[18000]\tvalid_0's rmse: 0.133303\n",
      "[18200]\tvalid_0's rmse: 0.133278\n",
      "[18400]\tvalid_0's rmse: 0.133251\n",
      "[18600]\tvalid_0's rmse: 0.133225\n",
      "[18800]\tvalid_0's rmse: 0.133208\n",
      "[19000]\tvalid_0's rmse: 0.133148\n",
      "[19200]\tvalid_0's rmse: 0.13314\n",
      "[19400]\tvalid_0's rmse: 0.133132\n",
      "[19600]\tvalid_0's rmse: 0.133118\n",
      "[19800]\tvalid_0's rmse: 0.133079\n",
      "[20000]\tvalid_0's rmse: 0.133074\n",
      "[20200]\tvalid_0's rmse: 0.133038\n",
      "[20400]\tvalid_0's rmse: 0.133\n",
      "[20600]\tvalid_0's rmse: 0.132968\n",
      "[20800]\tvalid_0's rmse: 0.132978\n",
      "[21000]\tvalid_0's rmse: 0.132968\n",
      "Early stopping, best iteration is:\n",
      "[20617]\tvalid_0's rmse: 0.132964\n",
      "Test RMSE :  0.13296388112931937\n",
      "Running CV Iteration Num : 3\n",
      "Training until validation scores don't improve for 400 rounds.\n",
      "[200]\tvalid_0's rmse: 0.377198\n",
      "[400]\tvalid_0's rmse: 0.256767\n",
      "[600]\tvalid_0's rmse: 0.2225\n",
      "[800]\tvalid_0's rmse: 0.210377\n",
      "[1000]\tvalid_0's rmse: 0.204268\n",
      "[1200]\tvalid_0's rmse: 0.201055\n",
      "[1400]\tvalid_0's rmse: 0.198864\n",
      "[1600]\tvalid_0's rmse: 0.197065\n",
      "[1800]\tvalid_0's rmse: 0.195594\n",
      "[2000]\tvalid_0's rmse: 0.194509\n",
      "[2200]\tvalid_0's rmse: 0.193591\n",
      "[2400]\tvalid_0's rmse: 0.192795\n",
      "[2600]\tvalid_0's rmse: 0.192066\n",
      "[2800]\tvalid_0's rmse: 0.191211\n",
      "[3000]\tvalid_0's rmse: 0.190437\n",
      "[3200]\tvalid_0's rmse: 0.189697\n",
      "[3400]\tvalid_0's rmse: 0.189095\n",
      "[3600]\tvalid_0's rmse: 0.188542\n",
      "[3800]\tvalid_0's rmse: 0.188011\n",
      "[4000]\tvalid_0's rmse: 0.187512\n",
      "[4200]\tvalid_0's rmse: 0.187079\n",
      "[4400]\tvalid_0's rmse: 0.186712\n",
      "[4600]\tvalid_0's rmse: 0.186327\n",
      "[4800]\tvalid_0's rmse: 0.185933\n",
      "[5000]\tvalid_0's rmse: 0.185628\n",
      "[5200]\tvalid_0's rmse: 0.185363\n",
      "[5400]\tvalid_0's rmse: 0.185091\n",
      "[5600]\tvalid_0's rmse: 0.184788\n",
      "[5800]\tvalid_0's rmse: 0.184486\n",
      "[6000]\tvalid_0's rmse: 0.184178\n",
      "[6200]\tvalid_0's rmse: 0.183922\n",
      "[6400]\tvalid_0's rmse: 0.18367\n",
      "[6600]\tvalid_0's rmse: 0.183316\n",
      "[6800]\tvalid_0's rmse: 0.18303\n",
      "[7000]\tvalid_0's rmse: 0.182765\n",
      "[7200]\tvalid_0's rmse: 0.182548\n",
      "[7400]\tvalid_0's rmse: 0.18236\n",
      "[7600]\tvalid_0's rmse: 0.182194\n",
      "[7800]\tvalid_0's rmse: 0.182005\n",
      "[8000]\tvalid_0's rmse: 0.181796\n",
      "[8200]\tvalid_0's rmse: 0.181588\n",
      "[8400]\tvalid_0's rmse: 0.181307\n",
      "[8600]\tvalid_0's rmse: 0.181076\n",
      "[8800]\tvalid_0's rmse: 0.180899\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9000]\tvalid_0's rmse: 0.180704\n",
      "[9200]\tvalid_0's rmse: 0.180508\n",
      "[9400]\tvalid_0's rmse: 0.180284\n",
      "[9600]\tvalid_0's rmse: 0.180083\n",
      "[9800]\tvalid_0's rmse: 0.179908\n",
      "[10000]\tvalid_0's rmse: 0.179699\n",
      "[10200]\tvalid_0's rmse: 0.179516\n",
      "[10400]\tvalid_0's rmse: 0.17939\n",
      "[10600]\tvalid_0's rmse: 0.17923\n",
      "[10800]\tvalid_0's rmse: 0.179083\n",
      "[11000]\tvalid_0's rmse: 0.178969\n",
      "[11200]\tvalid_0's rmse: 0.17884\n",
      "[11400]\tvalid_0's rmse: 0.178718\n",
      "[11600]\tvalid_0's rmse: 0.178588\n",
      "[11800]\tvalid_0's rmse: 0.178486\n",
      "[12000]\tvalid_0's rmse: 0.178388\n",
      "[12200]\tvalid_0's rmse: 0.178275\n",
      "[12400]\tvalid_0's rmse: 0.178146\n",
      "[12600]\tvalid_0's rmse: 0.178069\n",
      "[12800]\tvalid_0's rmse: 0.178001\n",
      "[13000]\tvalid_0's rmse: 0.177936\n",
      "[13200]\tvalid_0's rmse: 0.177883\n",
      "[13400]\tvalid_0's rmse: 0.177789\n",
      "[13600]\tvalid_0's rmse: 0.177678\n",
      "[13800]\tvalid_0's rmse: 0.177567\n",
      "[14000]\tvalid_0's rmse: 0.177489\n",
      "[14200]\tvalid_0's rmse: 0.177406\n",
      "[14400]\tvalid_0's rmse: 0.177335\n",
      "[14600]\tvalid_0's rmse: 0.177266\n",
      "[14800]\tvalid_0's rmse: 0.177189\n",
      "[15000]\tvalid_0's rmse: 0.177118\n",
      "[15200]\tvalid_0's rmse: 0.177014\n",
      "[15400]\tvalid_0's rmse: 0.17703\n",
      "[15600]\tvalid_0's rmse: 0.17702\n",
      "[15800]\tvalid_0's rmse: 0.176959\n",
      "[16000]\tvalid_0's rmse: 0.176936\n",
      "[16200]\tvalid_0's rmse: 0.176902\n",
      "[16400]\tvalid_0's rmse: 0.176855\n",
      "[16600]\tvalid_0's rmse: 0.176826\n",
      "[16800]\tvalid_0's rmse: 0.176829\n",
      "[17000]\tvalid_0's rmse: 0.176771\n",
      "[17200]\tvalid_0's rmse: 0.176744\n",
      "[17400]\tvalid_0's rmse: 0.176745\n",
      "[17600]\tvalid_0's rmse: 0.176718\n",
      "[17800]\tvalid_0's rmse: 0.176697\n",
      "[18000]\tvalid_0's rmse: 0.176669\n",
      "[18200]\tvalid_0's rmse: 0.176656\n",
      "[18400]\tvalid_0's rmse: 0.176616\n",
      "[18600]\tvalid_0's rmse: 0.176647\n",
      "Early stopping, best iteration is:\n",
      "[18391]\tvalid_0's rmse: 0.176613\n",
      "Test RMSE :  0.1766129872147391\n",
      "Running CV Iteration Num : 4\n",
      "Training until validation scores don't improve for 400 rounds.\n",
      "[200]\tvalid_0's rmse: 0.37099\n",
      "[400]\tvalid_0's rmse: 0.246358\n",
      "[600]\tvalid_0's rmse: 0.205272\n",
      "[800]\tvalid_0's rmse: 0.187882\n",
      "[1000]\tvalid_0's rmse: 0.178593\n",
      "[1200]\tvalid_0's rmse: 0.173488\n",
      "[1400]\tvalid_0's rmse: 0.169663\n",
      "[1600]\tvalid_0's rmse: 0.16689\n",
      "[1800]\tvalid_0's rmse: 0.164749\n",
      "[2000]\tvalid_0's rmse: 0.163074\n",
      "[2200]\tvalid_0's rmse: 0.161654\n",
      "[2400]\tvalid_0's rmse: 0.160561\n",
      "[2600]\tvalid_0's rmse: 0.159364\n",
      "[2800]\tvalid_0's rmse: 0.158288\n",
      "[3000]\tvalid_0's rmse: 0.157377\n",
      "[3200]\tvalid_0's rmse: 0.156481\n",
      "[3400]\tvalid_0's rmse: 0.155708\n",
      "[3600]\tvalid_0's rmse: 0.154835\n",
      "[3800]\tvalid_0's rmse: 0.154072\n",
      "[4000]\tvalid_0's rmse: 0.153349\n",
      "[4200]\tvalid_0's rmse: 0.152557\n",
      "[4400]\tvalid_0's rmse: 0.151862\n",
      "[4600]\tvalid_0's rmse: 0.151253\n",
      "[4800]\tvalid_0's rmse: 0.150688\n",
      "[5000]\tvalid_0's rmse: 0.150054\n",
      "[5200]\tvalid_0's rmse: 0.149541\n",
      "[5400]\tvalid_0's rmse: 0.149089\n",
      "[5600]\tvalid_0's rmse: 0.148673\n",
      "[5800]\tvalid_0's rmse: 0.148259\n",
      "[6000]\tvalid_0's rmse: 0.14786\n",
      "[6200]\tvalid_0's rmse: 0.147444\n",
      "[6400]\tvalid_0's rmse: 0.147101\n",
      "[6600]\tvalid_0's rmse: 0.14677\n",
      "[6800]\tvalid_0's rmse: 0.146488\n",
      "[7000]\tvalid_0's rmse: 0.146171\n",
      "[7200]\tvalid_0's rmse: 0.145836\n",
      "[7400]\tvalid_0's rmse: 0.145525\n",
      "[7600]\tvalid_0's rmse: 0.145222\n",
      "[7800]\tvalid_0's rmse: 0.14496\n",
      "[8000]\tvalid_0's rmse: 0.144773\n",
      "[8200]\tvalid_0's rmse: 0.144518\n",
      "[8400]\tvalid_0's rmse: 0.14428\n",
      "[8600]\tvalid_0's rmse: 0.144038\n",
      "[8800]\tvalid_0's rmse: 0.143785\n",
      "[9000]\tvalid_0's rmse: 0.143559\n",
      "[9200]\tvalid_0's rmse: 0.14329\n",
      "[9400]\tvalid_0's rmse: 0.14308\n",
      "[9600]\tvalid_0's rmse: 0.142863\n",
      "[9800]\tvalid_0's rmse: 0.142638\n",
      "[10000]\tvalid_0's rmse: 0.142454\n",
      "[10200]\tvalid_0's rmse: 0.142254\n",
      "[10400]\tvalid_0's rmse: 0.142074\n",
      "[10600]\tvalid_0's rmse: 0.141917\n",
      "[10800]\tvalid_0's rmse: 0.141751\n",
      "[11000]\tvalid_0's rmse: 0.14155\n",
      "[11200]\tvalid_0's rmse: 0.141389\n",
      "[11400]\tvalid_0's rmse: 0.141198\n",
      "[11600]\tvalid_0's rmse: 0.141016\n",
      "[11800]\tvalid_0's rmse: 0.140947\n",
      "[12000]\tvalid_0's rmse: 0.140847\n",
      "[12200]\tvalid_0's rmse: 0.140762\n",
      "[12400]\tvalid_0's rmse: 0.140637\n",
      "[12600]\tvalid_0's rmse: 0.140537\n",
      "[12800]\tvalid_0's rmse: 0.140447\n",
      "[13000]\tvalid_0's rmse: 0.140342\n",
      "[13200]\tvalid_0's rmse: 0.140261\n",
      "[13400]\tvalid_0's rmse: 0.140173\n",
      "[13600]\tvalid_0's rmse: 0.140056\n",
      "[13800]\tvalid_0's rmse: 0.139953\n",
      "[14000]\tvalid_0's rmse: 0.139863\n",
      "[14200]\tvalid_0's rmse: 0.139747\n",
      "[14400]\tvalid_0's rmse: 0.139634\n",
      "[14600]\tvalid_0's rmse: 0.139551\n",
      "[14800]\tvalid_0's rmse: 0.139512\n",
      "[15000]\tvalid_0's rmse: 0.13951\n",
      "[15200]\tvalid_0's rmse: 0.139473\n",
      "[15400]\tvalid_0's rmse: 0.139398\n",
      "[15600]\tvalid_0's rmse: 0.139328\n",
      "[15800]\tvalid_0's rmse: 0.139275\n",
      "[16000]\tvalid_0's rmse: 0.139217\n",
      "[16200]\tvalid_0's rmse: 0.139221\n",
      "[16400]\tvalid_0's rmse: 0.139127\n",
      "[16600]\tvalid_0's rmse: 0.139107\n",
      "[16800]\tvalid_0's rmse: 0.139034\n",
      "[17000]\tvalid_0's rmse: 0.139026\n",
      "[17200]\tvalid_0's rmse: 0.139028\n",
      "[17400]\tvalid_0's rmse: 0.138982\n",
      "[17600]\tvalid_0's rmse: 0.138948\n",
      "[17800]\tvalid_0's rmse: 0.138918\n",
      "[18000]\tvalid_0's rmse: 0.138877\n",
      "[18200]\tvalid_0's rmse: 0.138867\n",
      "[18400]\tvalid_0's rmse: 0.13884\n",
      "[18600]\tvalid_0's rmse: 0.138806\n",
      "[18800]\tvalid_0's rmse: 0.138789\n",
      "[19000]\tvalid_0's rmse: 0.138766\n",
      "[19200]\tvalid_0's rmse: 0.138751\n",
      "[19400]\tvalid_0's rmse: 0.138739\n",
      "[19600]\tvalid_0's rmse: 0.138686\n",
      "[19800]\tvalid_0's rmse: 0.138643\n",
      "[20000]\tvalid_0's rmse: 0.138619\n",
      "[20200]\tvalid_0's rmse: 0.138631\n",
      "[20400]\tvalid_0's rmse: 0.138621\n",
      "[20600]\tvalid_0's rmse: 0.138584\n",
      "[20800]\tvalid_0's rmse: 0.138546\n",
      "[21000]\tvalid_0's rmse: 0.138517\n",
      "[21200]\tvalid_0's rmse: 0.138519\n",
      "[21400]\tvalid_0's rmse: 0.138481\n",
      "[21600]\tvalid_0's rmse: 0.138454\n",
      "[21800]\tvalid_0's rmse: 0.138434\n",
      "[22000]\tvalid_0's rmse: 0.138422\n",
      "[22200]\tvalid_0's rmse: 0.138408\n",
      "[22400]\tvalid_0's rmse: 0.138415\n",
      "[22600]\tvalid_0's rmse: 0.138415\n",
      "Early stopping, best iteration is:\n",
      "[22295]\tvalid_0's rmse: 0.13838\n",
      "Test RMSE :  0.13837975835421443\n",
      "Running CV Iteration Num : 5\n",
      "Training until validation scores don't improve for 400 rounds.\n",
      "[200]\tvalid_0's rmse: 0.385528\n",
      "[400]\tvalid_0's rmse: 0.253139\n",
      "[600]\tvalid_0's rmse: 0.208782\n",
      "[800]\tvalid_0's rmse: 0.190034\n",
      "[1000]\tvalid_0's rmse: 0.180281\n",
      "[1200]\tvalid_0's rmse: 0.174764\n",
      "[1400]\tvalid_0's rmse: 0.170903\n",
      "[1600]\tvalid_0's rmse: 0.167875\n",
      "[1800]\tvalid_0's rmse: 0.165302\n",
      "[2000]\tvalid_0's rmse: 0.163384\n",
      "[2200]\tvalid_0's rmse: 0.16174\n",
      "[2400]\tvalid_0's rmse: 0.160205\n",
      "[2600]\tvalid_0's rmse: 0.158565\n",
      "[2800]\tvalid_0's rmse: 0.157234\n",
      "[3000]\tvalid_0's rmse: 0.156057\n",
      "[3200]\tvalid_0's rmse: 0.154856\n",
      "[3400]\tvalid_0's rmse: 0.153801\n",
      "[3600]\tvalid_0's rmse: 0.15282\n",
      "[3800]\tvalid_0's rmse: 0.151777\n",
      "[4000]\tvalid_0's rmse: 0.150889\n",
      "[4200]\tvalid_0's rmse: 0.150015\n",
      "[4400]\tvalid_0's rmse: 0.149239\n",
      "[4600]\tvalid_0's rmse: 0.148497\n",
      "[4800]\tvalid_0's rmse: 0.147852\n",
      "[5000]\tvalid_0's rmse: 0.147179\n",
      "[5200]\tvalid_0's rmse: 0.146474\n",
      "[5400]\tvalid_0's rmse: 0.14584\n",
      "[5600]\tvalid_0's rmse: 0.145229\n",
      "[5800]\tvalid_0's rmse: 0.144618\n",
      "[6000]\tvalid_0's rmse: 0.144128\n",
      "[6200]\tvalid_0's rmse: 0.143566\n",
      "[6400]\tvalid_0's rmse: 0.143046\n",
      "[6600]\tvalid_0's rmse: 0.14251\n",
      "[6800]\tvalid_0's rmse: 0.141977\n",
      "[7000]\tvalid_0's rmse: 0.141517\n",
      "[7200]\tvalid_0's rmse: 0.141056\n",
      "[7400]\tvalid_0's rmse: 0.140665\n",
      "[7600]\tvalid_0's rmse: 0.140169\n",
      "[7800]\tvalid_0's rmse: 0.139784\n",
      "[8000]\tvalid_0's rmse: 0.139426\n",
      "[8200]\tvalid_0's rmse: 0.138895\n",
      "[8400]\tvalid_0's rmse: 0.138519\n",
      "[8600]\tvalid_0's rmse: 0.138144\n",
      "[8800]\tvalid_0's rmse: 0.137824\n",
      "[9000]\tvalid_0's rmse: 0.137441\n",
      "[9200]\tvalid_0's rmse: 0.137039\n",
      "[9400]\tvalid_0's rmse: 0.136635\n",
      "[9600]\tvalid_0's rmse: 0.136308\n",
      "[9800]\tvalid_0's rmse: 0.136008\n",
      "[10000]\tvalid_0's rmse: 0.135718\n",
      "[10200]\tvalid_0's rmse: 0.135404\n",
      "[10400]\tvalid_0's rmse: 0.135149\n",
      "[10600]\tvalid_0's rmse: 0.134867\n",
      "[10800]\tvalid_0's rmse: 0.134581\n",
      "[11000]\tvalid_0's rmse: 0.134328\n",
      "[11200]\tvalid_0's rmse: 0.134076\n",
      "[11400]\tvalid_0's rmse: 0.133855\n",
      "[11600]\tvalid_0's rmse: 0.133587\n",
      "[11800]\tvalid_0's rmse: 0.133328\n",
      "[12000]\tvalid_0's rmse: 0.133117\n",
      "[12200]\tvalid_0's rmse: 0.132893\n",
      "[12400]\tvalid_0's rmse: 0.132667\n",
      "[12600]\tvalid_0's rmse: 0.13247\n",
      "[12800]\tvalid_0's rmse: 0.132262\n",
      "[13000]\tvalid_0's rmse: 0.132049\n",
      "[13200]\tvalid_0's rmse: 0.131846\n",
      "[13400]\tvalid_0's rmse: 0.131658\n",
      "[13600]\tvalid_0's rmse: 0.13148\n",
      "[13800]\tvalid_0's rmse: 0.131311\n",
      "[14000]\tvalid_0's rmse: 0.131122\n",
      "[14200]\tvalid_0's rmse: 0.130949\n",
      "[14400]\tvalid_0's rmse: 0.130817\n",
      "[14600]\tvalid_0's rmse: 0.130657\n",
      "[14800]\tvalid_0's rmse: 0.130517\n",
      "[15000]\tvalid_0's rmse: 0.130359\n",
      "[15200]\tvalid_0's rmse: 0.130223\n",
      "[15400]\tvalid_0's rmse: 0.130072\n",
      "[15600]\tvalid_0's rmse: 0.129922\n",
      "[15800]\tvalid_0's rmse: 0.129786\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[16000]\tvalid_0's rmse: 0.129686\n",
      "[16200]\tvalid_0's rmse: 0.129567\n",
      "[16400]\tvalid_0's rmse: 0.129437\n",
      "[16600]\tvalid_0's rmse: 0.129367\n",
      "[16800]\tvalid_0's rmse: 0.129286\n",
      "[17000]\tvalid_0's rmse: 0.129194\n",
      "[17200]\tvalid_0's rmse: 0.129102\n",
      "[17400]\tvalid_0's rmse: 0.128987\n",
      "[17600]\tvalid_0's rmse: 0.128918\n",
      "[17800]\tvalid_0's rmse: 0.128818\n",
      "[18000]\tvalid_0's rmse: 0.128743\n",
      "[18200]\tvalid_0's rmse: 0.128655\n",
      "[18400]\tvalid_0's rmse: 0.128555\n",
      "[18600]\tvalid_0's rmse: 0.128479\n",
      "[18800]\tvalid_0's rmse: 0.128409\n",
      "[19000]\tvalid_0's rmse: 0.128317\n",
      "[19200]\tvalid_0's rmse: 0.128245\n",
      "[19400]\tvalid_0's rmse: 0.128176\n",
      "[19600]\tvalid_0's rmse: 0.128096\n",
      "[19800]\tvalid_0's rmse: 0.128039\n",
      "[20000]\tvalid_0's rmse: 0.127974\n",
      "[20200]\tvalid_0's rmse: 0.127921\n",
      "[20400]\tvalid_0's rmse: 0.127881\n",
      "[20600]\tvalid_0's rmse: 0.127819\n",
      "[20800]\tvalid_0's rmse: 0.127762\n",
      "[21000]\tvalid_0's rmse: 0.127707\n",
      "[21200]\tvalid_0's rmse: 0.127664\n",
      "[21400]\tvalid_0's rmse: 0.127617\n",
      "[21600]\tvalid_0's rmse: 0.127576\n",
      "[21800]\tvalid_0's rmse: 0.127531\n",
      "[22000]\tvalid_0's rmse: 0.127482\n",
      "[22200]\tvalid_0's rmse: 0.127434\n",
      "[22400]\tvalid_0's rmse: 0.127384\n",
      "[22600]\tvalid_0's rmse: 0.127327\n",
      "[22800]\tvalid_0's rmse: 0.12728\n",
      "[23000]\tvalid_0's rmse: 0.127245\n",
      "[23200]\tvalid_0's rmse: 0.127188\n",
      "[23400]\tvalid_0's rmse: 0.127146\n",
      "[23600]\tvalid_0's rmse: 0.127119\n",
      "[23800]\tvalid_0's rmse: 0.127088\n",
      "[24000]\tvalid_0's rmse: 0.127056\n",
      "[24200]\tvalid_0's rmse: 0.127006\n",
      "[24400]\tvalid_0's rmse: 0.126985\n",
      "[24600]\tvalid_0's rmse: 0.12697\n",
      "[24800]\tvalid_0's rmse: 0.126947\n",
      "[25000]\tvalid_0's rmse: 0.126917\n",
      "[25200]\tvalid_0's rmse: 0.126893\n",
      "[25400]\tvalid_0's rmse: 0.126866\n",
      "[25600]\tvalid_0's rmse: 0.126857\n",
      "[25800]\tvalid_0's rmse: 0.126815\n",
      "[26000]\tvalid_0's rmse: 0.126789\n",
      "[26200]\tvalid_0's rmse: 0.126789\n",
      "[26400]\tvalid_0's rmse: 0.126748\n",
      "[26600]\tvalid_0's rmse: 0.126729\n",
      "[26800]\tvalid_0's rmse: 0.126707\n",
      "[27000]\tvalid_0's rmse: 0.126689\n",
      "[27200]\tvalid_0's rmse: 0.126674\n",
      "[27400]\tvalid_0's rmse: 0.126657\n",
      "[27600]\tvalid_0's rmse: 0.126632\n",
      "[27800]\tvalid_0's rmse: 0.126622\n",
      "[28000]\tvalid_0's rmse: 0.126646\n",
      "Early stopping, best iteration is:\n",
      "[27799]\tvalid_0's rmse: 0.126622\n",
      "Test RMSE :  0.12662180623325617\n",
      "CV RMSE :  0.14163254972829442\n"
     ]
    }
   ],
   "source": [
    "IterationNum = 1\n",
    "for train_index, test_index in kf.split(train02):\n",
    "    print(\"Running CV Iteration Num :\", IterationNum)\n",
    "    MOD_DATA_2_TRAIN, MOD_DATA_2_TEST = train02.iloc[train_index], train02.iloc[test_index]\n",
    "    \n",
    "    parameters = {  'objective': 'regression',\n",
    "                    'metric': 'rmse',\n",
    "                    'boosting': 'gbdt',\n",
    "                    'feature_fraction': 0.4,\n",
    "                    'bagging_fraction': 0.6,\n",
    "                    'bagging_freq' : 0,\n",
    "                    'learning_rate': 0.005,\n",
    "                    'min_data_in_leaf': 2,\n",
    "                    'max_depth': 4,\n",
    "                    'seed': 500,\n",
    "                    'max_bin': 75,\n",
    "                    'min_data_in_bin': 5,\n",
    "                    'verbosity': -1,\n",
    "                    'silent': -1  }\n",
    "    \n",
    "    X_TRAIN = pd.DataFrame(MOD_DATA_2_TRAIN[feature_names])\n",
    "    Y_TRAIN = MOD_DATA_2_TRAIN[\"Price\"]\n",
    "                \n",
    "    X_TEST = pd.DataFrame(MOD_DATA_2_TEST[feature_names])\n",
    "    Y_TEST = MOD_DATA_2_TEST[\"Price\"]\n",
    "    \n",
    "    train_data = lgb.Dataset(X_TRAIN,\n",
    "                             label = Y_TRAIN)\n",
    "    valid_data = lgb.Dataset(X_TEST,\n",
    "                             label = Y_TEST)\n",
    "    lgb_model = lgb.train(parameters,\n",
    "                          train_data,\n",
    "                          valid_sets = valid_data,\n",
    "                          num_boost_round = 10000000,\n",
    "                          early_stopping_rounds = 400,\n",
    "                          verbose_eval = 200)\n",
    "    MOD_DATA_2_TEST['Predicted_Model_Value'] = lgb_model.predict(pd.DataFrame(MOD_DATA_2_TEST[feature_names]))\n",
    "    \n",
    "    if(IterationNum == 1):\n",
    "        CV_SCORED_DATA = MOD_DATA_2_TEST.copy(deep=True)\n",
    "        CV_SCORED_DATA.reset_index(drop = True, inplace = True)\n",
    "        test_scored = lgb_model.predict(pd.DataFrame(test01[feature_names]))\n",
    "    else:\n",
    "        CV_SCORED_DATA = pd.concat([CV_SCORED_DATA,MOD_DATA_2_TEST])\n",
    "        CV_SCORED_DATA.reset_index(drop = True, inplace = True)\n",
    "        test_scored = test_scored + lgb_model.predict(pd.DataFrame(test01[feature_names]))\n",
    "                    \n",
    "    IterationNum = IterationNum + 1\n",
    "    \n",
    "    print(\"Test RMSE : \",sqrt(mean_squared_error(MOD_DATA_2_TEST[\"Price\"], MOD_DATA_2_TEST['Predicted_Model_Value'])))\n",
    "    \n",
    "print(\"CV RMSE : \",sqrt(mean_squared_error(CV_SCORED_DATA[\"Price\"], CV_SCORED_DATA['Predicted_Model_Value'])))\n",
    "#CV RMSE :  0.1426465946675941\n",
    "#LB: 0.9462"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DescribeResult(nobs=1234, minmax=(0.3328331518393663, 4.345887503783606), mean=1.9852669520285584, variance=0.5100080643313538, skewness=0.7459720756831557, kurtosis=0.13212260609489102)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from scipy import stats\n",
    "test_scored2 = test_scored / 5.0\n",
    "stats.describe(test_scored2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_scored3 = pd.DataFrame({'Price' : np.exp(test_scored2)-1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.749518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.057949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16.864857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.199543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.612711</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Price\n",
       "0   2.749518\n",
       "1   3.057949\n",
       "2  16.864857\n",
       "3   4.199543\n",
       "4   4.612711"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_scored3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "CV_SCORED_DATA.to_csv(\"C:\\\\Kaggle\\\\Cars\\\\CV_Scored\\\\20190716_LGB01_CVTRAIN_DS.csv\",\n",
    "                      index = False)\n",
    "test_scored3.to_csv(\"C:\\\\Kaggle\\\\Cars\\\\Submission\\\\20190716_LGB01_TEST_DS.csv\",\n",
    "                    index = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
